#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <sstream>
#include <iterator>
#include <algorithm>

using namespace std;
#define _SKIP_LINE_ do{scanf("%*[^\n]"); getc(stdin);}while(0)
stringstream tokens(stringstream::in | stringstream::out);

short Max_Element(vector<short>::const_iterator start, vector<short>::const_iterator end) {
	short max = *start;
	short pos = 1;
	short count = 2;
	start++;
	while(start != end) {
		if(max < *start) {
			max = *start;
			pos = count;
		}
		count++;
		start++;
	}
	return pos;
}

void flip_sort(vector<short>& pancakes) {
	short sz = pancakes.size();
	copy(pancakes.begin(), pancakes.end()-1, ostream_iterator<short>(cout, " "));
	cout << pancakes[sz-1] << endl;
	short flip = 0;
	while (sz > 0) {
		flip = Max_Element(pancakes.begin(), pancakes.begin()+sz);
		if(flip != sz) {
			if(flip > 1) {
				reverse(pancakes.begin(), pancakes.begin()+flip);
				cout << pancakes.size()- flip + 1 << " "; 
			}
			reverse(pancakes.begin(), pancakes.begin()+sz);
			cout << pancakes.size()- sz + 1 << " "; 
		}
		sz--;
	}
	cout << 0 << endl;
}

/* main
 *  * */
int main() {
	string line;
	vector<short> pancakes;
	//bool entry = true;
	while(cin.eof() != true) {
		getline(cin, line);
		tokens.clear();
		tokens << line;
		copy(istream_iterator<short>(tokens), istream_iterator<short>(), back_inserter(pancakes));
		if(pancakes.empty() == false) {
			//if(entry == false) cout << endl;
			//else entry = false;
			flip_sort(pancakes);
			pancakes.clear();
		}
	}
	return 0;
}
